package cn.com.oyat.idea.util;

public class SoapResponseUtil {

    private SoapResponseUtil() {
        // 工具类，防止实例化
    }

    public static String createSuccessResponse(String actionName) {
        return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/\" \n" +
                "            s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +
                "  <s:Body>\n" +
                "    <u:" + actionName + "Response \n" +
                "        xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">\n" +
                "    </u:" + actionName + "Response>\n" +
                "  </s:Body>\n" +
                "</s:Envelope>";
    }

    public static String createErrorResponse(String errorCode, String errorDescription) {
        return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/\" \n" +
                "            s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +
                "  <s:Body>\n" +
                "    <s:Fault>\n" +
                "      <faultcode>s:Client</faultcode>\n" +
                "      <faultstring>UPnPError</faultstring>\n" +
                "      <detail>\n" +
                "        <UPnPError xmlns=\"urn:schemas-upnp-org:control-1-0\">\n" +
                "          <errorCode>" + errorCode + "</errorCode>\n" +
                "          <errorDescription>" + errorDescription + "</errorDescription>\n" +
                "        </UPnPError>\n" +
                "      </detail>\n" +
                "    </s:Fault>\n" +
                "  </s:Body>\n" +
                "</s:Envelope>";
    }

    public static String createPositionInfoResponse(String videoUrl) {
        String safeUrl = videoUrl != null ? videoUrl : "";
        return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/\" \n" +
                "            s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +
                "  <s:Body>\n" +
                "    <u:GetPositionInfoResponse \n" +
                "        xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">\n" +
                "      <Track>1</Track>\n" +
                "      <TrackDuration>0:10:00</TrackDuration>\n" +
                "      <TrackMetaData></TrackMetaData>\n" +
                "      <TrackURI>" + safeUrl + "</TrackURI>\n" +
                "      <RelTime>0:01:30</RelTime>\n" +
                "      <AbsTime>0:01:30</AbsTime>\n" +
                "      <RelCount>2147483647</RelCount>\n" +
                "      <AbsCount>2147483647</AbsCount>\n" +
                "    </u:GetPositionInfoResponse>\n" +
                "  </s:Body>\n" +
                "</s:Envelope>";
    }

    public static String createTransportInfoResponse() {
        return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
                "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/\" \n" +
                "            s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" +
                "  <s:Body>\n" +
                "    <u:GetTransportInfoResponse \n" +
                "        xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">\n" +
                "      <CurrentTransportState>PLAYING</CurrentTransportState>\n" +
                "      <CurrentTransportStatus>OK</CurrentTransportStatus>\n" +
                "      <CurrentSpeed>1</CurrentSpeed>\n" +
                "    </u:GetTransportInfoResponse>\n" +
                "  </s:Body>\n" +
                "</s:Envelope>";
    }
}